const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      fsid:'',
      wMoney:'',
      walletBalance:0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
      var that = this;
      that.setData({
          fsid: options.fsid
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  bindCancel: function() {
    wx.navigateBack({})
  },
  bindSave: function() {
      var that = this;
      //判断输入框为空
      var input = that.data.wMoney; // 获取充值金额
      if (input * 1 >= 1) {
          wx.request({
              url: 'https://www.brvpmusic.com/certification/withdraw/apply',
              // url: 'http://3s.dkys.org:25333/certification/withdraw/apply',
              method: 'GET',
              header: {
                  'content-type': 'application/x-www-form-urlencoded'
              },
              data: {
                  fsid:that.data.fsid,
                  wMoney: that.data.wMoney,
              },
              success: function(res) {
                  console.log(res.data);

                  if (res.data.code==200){
                      var result = res.data.body;
                      console.log("钱包余额:" + result.walletBalance);
                      that.setData({
                          walletBalance: result.walletBalance
                      });
                      console.log('提现成功');
                      wx.showToast({
                          title: '您的提现申请提交成功',
                          icon: 'none',
                          duration: 1000
                      });
                      setTimeout(() => {
                          wx.navigateBack({
                              delta: 1
                          })
                      }, 1000);
                  }else if(res.data.code==400){
                      wx.showToast({
                          title: res.data.message,
                          icon: 'none',
                          duration: 1000
                      });
                  }else {
                      wx.showToast({
                          title: res.data.message,
                          icon: 'none',
                          duration: 1000
                      });
                  }
              }
          })
      } else {
          if (input * 1 < 1) {
              wx.showToast({
                  title: '提现金额不能少于1元!',
                  icon: 'none',
                  duration: 2000
              });
          } else {
              wx.showToast({
                  title: '提现金额不能为空!',
                  icon: 'false',
                  duration: 2000
              });
          }
          return false;
      }
  },
    changeInputValue(ev) {
        this.setData({
            wMoney: ev.detail.value,
        })
    }
})